<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="../css/all.css">
    <link rel="stylesheet" href="../css/foot.css">
    <link rel="stylesheet" href="../css/login/head.css">
    <link rel="stylesheet" href="../css/login/body.css">
    <script src="../js/ajax.js"></script>
</head>
<body>
    <div>
        <div class="head">
            <div class="content item_clear">
               <div class="head_img floatl">
                    品优购
               </div> 
            </div>
        </div>
        <div class="body">
            <div class="banner content item_clear posi_relative">
                <div class="phone">
                    <form action="">
                        <input type="text" placeholder="手机节">
                        <input type="submit" value="搜索">
                    </form>
                </div>
                <div class="body_login floatr">
                    <form  action="index.html" onsubmit="return validateForm(user,passwords)" method="post">
                    <!-- <div></div> -->
                        <div class="item_clear">
                            <label for="" class="floatl"><a href="">扫描登录</a> </label><span class="floatl">|</span><label for="" class="floatl"><a href="">账号登录</a></label>
                        </div>
                        <p>公共场所不建议登录，以免账号丢失</p>
                        <div class="user">
                            <input type="text" value="" id="user">
                        </div>
                        <div class="password">
                            <input type="password" value="" id="passwords">
                        </div>
                        <div class="longin_ch item_clear">
                            <input type="checkbox" name="" id="checkpassword"><span>自动登录</span>
                            <b><a href="">忘记密码？</a></b>
                        </div>
                        <div class="lg_bt">
                            <button type="submit" >登录</button>
                        </div>
                        <div class="longin_img">
                            <div class="floatl">

                            </div>
                            <div class="floatr">
                                <a href="./register.html" >立即注册</a>
                            </div>
                            
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="foot">
            <div class="content">
                <div class="foot_span1">
                    <ul class="item_clear">
                        <li><a href="">关于我们</a><span>|</span></li>
                        <li><a href="">联系我们</a><span>|</span></li>
                        <li><a href="">联系客服</a><span>|</span></li>
                        <li><a href="">商家入驻</a><span>|</span></li>
                        <li><a href="">营销中心</a><span>|</span></li>
                        <li><a href="">手机品优购</a><span>|</span></li>
                        <li><a href="">友情链接</a><span>|</span></li>
                        <li><a href="">销售联盟</a><span>|</span></li>
                        <li><a href="">品优购社区</a><span>|</span></li>
                        <li><a href="">品优购公益</a><span>|</span></li>
                        <li><a href="">English Site</a><span>|</span></li>
                        <li><a href="">Contact U</a></li>
                    </ul>
                </div>
                <div class="foot_span2">
                    <p>地址：北京市昌平区建材西路金燕龙办公楼一层&nbsp;邮编：100096&nbsp;电话：400-618-4000&nbsp;传真：010-82935100&nbsp;邮箱：zhanghj+itcast.cn</p>
                </div>
                <div class="foot_span3">
                    京ICP&nbsp;08001421&nbsp;号京公网安备&nbsp;110108007702
                </div>
            </div>   
        </div>
    </div>
    <script>
        let btnEle = document.querySelector(".lg_bt > button");
        btnEle.onclick = function ( event ){
            let e = event || window.event ;
            e.preventDefault();
            let username = document.querySelector("#user").value;
            let pwd = document.querySelector("#passwords").value;
            ajax({
                url:"../php/login.php",
                method:"post",
                dataType:"json",
                data:{
                    username,
                    pwd,
                },
                success(data){
                    // console.log(data);
                    if( data['status'] == 1 ){
                        if( data['ulevel'] == 3 ){
                            window.location.href = `./admin/admin.html` ;
                        } else {
                            window.location.href = `./index.html?id=${data['id']}` ; 
                        }
                    }
                }
            });
        }
    </script>
</body>
</html>